<?php
    require_once('ZervWizard.php');
 
    class CheckoutWizard extends ZervWizard
    {
    	public static $step;
    	public $image;
    	
        function CheckoutWizard()
        {
            session_start();
            parent::ZervWizard($_SESSION, __CLASS__);

            $this->addStep('programdetails'	, 'Program bilgilerini giriniz');
            $this->addStep('uploadposter'	, 'Poster yükleyin');
            $this->addStep('playlist'		, 'Playlist oluşturun');
            $this->addStep('scheduletime'	, 'Programınız için zaman dilimi seçiniz');
        }
 
        function prepare_programdetails()
        {
            $this->loadTypes();
        }

        function process_programdetails(&$form)
        {
        	
            $name = $this->coalesce($form['name']);
            if (strlen($name) > 0)
                $this->setValue('name', $name);
            else
                $this->addError('name', 'Lütfen program ismini giriniz');

            $type = $this->coalesce($form['type']);
            $this->loadTypes();
            if (array_key_exists($type, $this->types))
                $this->setValue('type', $type);
            else
                $this->addError('type', 'Lütfen program türü seçiniz');
 
            return !$this->isError();
        }
 
        function process_uploadposter(&$form)
        {
        	
 			$image = $_POST['image'];

            if (strlen($image) > 0) {
                $this->setValue('image', $image);
            }
            else {
                $this->addError('image', 'Lütfen bir poster seçiniz');
            }
 
            return !$this->isError();
        }


        function process_playlist(&$form)
        {
			$music = $this->coalesce($form['music']);
 			
            if (strlen($music[0]) > 0) {
                $this->setValue('music', $music);
            }
            else {
                $this->addError('music', 'Lütfen playlist oluşturun');
            }
 
            return !$this->isError();
        }
 
        function process_scheduletime(&$form)
        {
            $scheduletime = (bool) $this->coalesce($form['publishDate'], true);
 			
             if (strlen($scheduletime) > 0)
                $this->setValue('publishDate', $scheduletime);
            else
                $this->addError('publishDate', 'Lütfen program tarihi seçin');
                
            return $scheduletime;
        }
 
        /**TODO:will be completed**/
        function completeCallback()
        {

	        $user = "root";
            $password   = "5869715";
            $database   = "complaint";
            $db_address = "localhost";
			
            $dbh = mysql_connect( $db_address, $user, $password ) or die ('I cannot connect to the database because: ' . mysql_error()); 
			
            $dbh = mysql_select_db( $database ) or die('cannot select db');
			
            $submitname    = $this->getValue('name');
            $submittype    = $this->getValue('type');
            $submitimage    = $this->getValue('image');
			$submitplaylist    = $this->getValue('music');
			$submitpublishDate    = $this->getValue('publishDate');
		
			Yii::log($submitname.'***name***','error');
			Yii::log($submittype.'***$submittype***','error');
			Yii::log($submitimage.'***$submitimage***','error');
			Yii::log($submitplaylist.'***$submitplaylist***','error');
			Yii::log($submitpublishDate.'***$submitpublishDate***','error');
            //$query  = "INSERT INTO playlist (id, showId, name, order, endpoint) ";
            //$query .= "VALUES ('', '".$submitname."', '".$submitemail."', '".$submitcountry."')";
			
            //$dbh = mysql_query( $query ) or die('failed insert query');
			
            //$dbh = mysql_close() or die('something bad happened during myqsl_close');
        }

        function loadTypes()
        {
            $this->types = array('0' => 'Jazz',
                                     '1' => 'Blues',
                                     '2' => 'Disko',
                                     '3' => 'Hop',
                                     '4' => 'Pop');
        }
  
    }
?>